/**
 * 
 */
package com.module.hq.bus.maps;

import com.dalonedrau.jogl.engine.GlobalConsts;
import com.dalonedrau.jogl.engine.Interactive;
import com.dalonedrau.jogl.engine.JOGLErrorHandler;
import com.dalonedrau.pool.PooledStringBuilder;
import com.dalonedrau.pool.StringBuilderPool;
import com.module.hq.bus.globals.HQGlobals;
import com.module.hq.bus.player.Akron;
import com.module.hq.bus.player.Galadrus;
import com.module.hq.bus.player.Strom;
import com.module.hq.bus.player.Zull;
import com.module.hq.engine.HQController;
import com.module.hq.engine.HQInteractiveObject;
import com.module.hq.engine.HQMap;
import com.module.hq.engine.HQPlayer;
import com.module.hq.engine.HQScript;
import com.module.hq.engine.HQTurn;
import com.module.hq.view.DungeonScreenView;

/**
 * @author Donald
 */
public class Maze00 {
	/**
	 * the one and only instance of the <code>Maze00</code> class.
	 */
	private static Maze00	instance;
	/**
	 * Gives access to the singleton instance of {@link Maze00}.
	 * @return {@link Maze00}
	 */
	public static Maze00 getInstance() {
		if (Maze00.instance == null) {
			Maze00.instance = new Maze00();
		}
		return Maze00.instance;
	}
	public void load() {
		try {
			int pc = HQController.getInstance().getPcId();
			HQInteractiveObject io =
					(HQInteractiveObject) Interactive.getInstance().getIO(pc);
			HQTurn.getInstance().addIO(pc);
			switch (io.getPCData().getProfession()) {
			case HQGlobals.CLASS_00BARBARIAN:
				// load barbarian at 1,1
				HQMap.getInstance().addIOToMap(1, 1, io);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"BARBARIAN has entered the maze.\n");
				// create new IOS to play alongside
				HQInteractiveObject ioDwarf =
						HQPlayer.getInstance().getFreshHero(new Strom());
				HQMap.getInstance().addIOToMap(1, 24, ioDwarf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"DWARF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioDwarf.getRefId());
				ioDwarf = null;
				HQInteractiveObject ioElf =
						HQPlayer.getInstance().getFreshHero(new Galadrus());
				HQMap.getInstance().addIOToMap(34, 24, ioElf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"ELF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioElf.getRefId());
				ioElf = null;
				HQInteractiveObject ioWizard =
						HQPlayer.getInstance().getFreshHero(new Akron());
				HQMap.getInstance().addIOToMap(34, 1, ioWizard);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"WIZARD has entered the maze.\n");
				HQTurn.getInstance().addIO(ioWizard.getRefId());
				ioWizard = null;
				break;
			case HQGlobals.CLASS_01DWARF:
				// load dwarf at 1,24
				HQMap.getInstance().addIOToMap(1, 24, io);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"DWARF has entered the maze.\n");
				// create new IOS to play alongside
				HQInteractiveObject ioBarbarian =
						HQPlayer.getInstance().getFreshHero(new Zull());
				HQMap.getInstance().addIOToMap(1, 1, ioBarbarian);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"BARBARIAN has entered the maze.\n");
				HQTurn.getInstance().addIO(ioBarbarian.getRefId());
				ioBarbarian = null;
				ioElf = HQPlayer.getInstance().getFreshHero(new Galadrus());
				HQMap.getInstance().addIOToMap(34, 24, ioElf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"ELF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioElf.getRefId());
				ioElf = null;
				ioWizard = HQPlayer.getInstance().getFreshHero(new Akron());
				HQMap.getInstance().addIOToMap(34, 1, ioWizard);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"WIZARD has entered the maze.\n");
				HQTurn.getInstance().addIO(ioWizard.getRefId());
				ioWizard = null;
				break;
			case HQGlobals.CLASS_02ELF:
				// load elf at 34,24
				HQMap.getInstance().addIOToMap(34, 24, io);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"ELF has entered the maze.\n");
				// create new IOS to play alongside
				ioBarbarian = HQPlayer.getInstance().getFreshHero(new Zull());
				HQMap.getInstance().addIOToMap(1, 1, ioBarbarian);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"BARBARIAN has entered the maze.\n");
				HQTurn.getInstance().addIO(ioBarbarian.getRefId());
				ioBarbarian = null;
				ioDwarf = HQPlayer.getInstance().getFreshHero(new Strom());
				HQMap.getInstance().addIOToMap(1, 24, ioDwarf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"DWARF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioDwarf.getRefId());
				ioDwarf = null;
				ioWizard = HQPlayer.getInstance().getFreshHero(new Akron());
				HQMap.getInstance().addIOToMap(34, 1, ioWizard);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"WIZARD has entered the maze.\n");
				HQTurn.getInstance().addIO(ioWizard.getRefId());
				ioWizard = null;
				break;
			case HQGlobals.CLASS_03WIZARD:
				// load wizard at 34,1
				HQMap.getInstance().addIOToMap(34, 1, io);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"WIZARD has entered the maze.\n");
				// create new IOS to play alongside
				ioBarbarian = HQPlayer.getInstance().getFreshHero(new Zull());
				HQMap.getInstance().addIOToMap(1, 1, ioBarbarian);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"BARBARIAN has entered the maze.\n");
				HQTurn.getInstance().addIO(ioBarbarian.getRefId());
				ioBarbarian = null;
				ioDwarf = HQPlayer.getInstance().getFreshHero(new Strom());
				HQMap.getInstance().addIOToMap(1, 24, ioDwarf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"DWARF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioDwarf.getRefId());
				ioDwarf = null;
				ioElf = HQPlayer.getInstance().getFreshHero(new Galadrus());
				HQMap.getInstance().addIOToMap(34, 24, ioElf);
				DungeonScreenView.getInstance().sendPlayerMessage(
						"ELF has entered the maze.\n");
				HQTurn.getInstance().addIO(ioElf.getRefId());
				ioElf = null;
				break;
			default:
				PooledStringBuilder sb =
						StringBuilderPool.getInstance().getStringBuilder();
				sb.append("Invalid character profession: ");
				sb.append(io.getPCData().getProfession());
				Exception ex = new Exception(sb.toString());
				sb.returnToPool();
				JOGLErrorHandler.getInstance().fatalError(ex);
				break;
			}
			// add no monsters to this map
			io = null;
			DungeonScreenView.getInstance().sendPlayerMessage(
					"---------- Turn 1 ----------\n");
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
}
